package com.xcf.service.business.bookingcargo.impl;

import cn.com.xcf.dao.mapper.BillBusOptHisMapper;
import cn.com.xcf.dao.mapper.FactBookingCargoMapper;
import cn.com.xcf.dao.mapper.FactBookingNoteMapper;
import cn.com.xcf.dao.model.BillBusOptHis;
import cn.com.xcf.dao.model.FactBookingCargo;
import cn.com.xcf.dao.model.FactBookingNote;
import com.google.common.collect.Maps;
import com.xcf.entity.system.User;
import com.xcf.service.business.bookingcargo.BookingCargoService;
import com.xcf.service.business.bookingcargo.BookingNoteService;
import com.xcf.util.Const;
import com.xcf.util.Jurisdiction;
import com.xcf.util.PageData;

import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * author ：yangchao
 * date ：2017/11/24
 * Description：
 *
 * @version V1.0
 */
@Service
public class BookingNoteServiceImpl implements BookingNoteService {

    @Autowired
    private FactBookingNoteMapper bookingNoteMapper;
	@Autowired
	private BillBusOptHisMapper billBusOptHisMapper;


    @Override
    public FactBookingNote queryByBillCode(String billCode) {
        Map param = Maps.newHashMap();
        param.put("billCode", billCode);
        List<FactBookingNote> list = bookingNoteMapper.queryByParams(param);
        if(list.size() > 0){
            return list.get(0);
        }
        return null;
    }



	@Override
	public boolean updateInfo(FactBookingNote factBookingNote) {
		
		return bookingNoteMapper.updateById(factBookingNote) > 0 ? true : false;
	}



	@Override
	public List<Map> findTrailer(PageData pd) {
		// TODO Auto-generated method stub
		return bookingNoteMapper.findTrailer(pd);
	}



	@Override
	public List<Map> findCustomsMode(PageData pd) {
		
		return bookingNoteMapper.findCustomsMode(pd);
	}



	@Override
	public List<Map> findCustoms(PageData pd) {
		return bookingNoteMapper.findCustoms(pd);
	}



	@Override
	public List<Map> findBillType(PageData pd) {
		return bookingNoteMapper.findBillType(pd);
	}



	@Override
	public int saveTrailer(PageData pd) {
		
		return bookingNoteMapper.saveTrailer(pd);
	}



	@Override
	public void updateTrailer(PageData pd) {
		bookingNoteMapper.updateTrailer(pd);
		
	}



	@Override
	public void deleteTrailer(PageData pd) {
		bookingNoteMapper.deleteTrailer(pd);
		
	}



	@Override
	public void updateBookNoteInfo(PageData pd) {
		bookingNoteMapper.updateBookNoteInfo(pd);
		
	}



	@Override
	public List<Map> findRate(PageData pd) {
		
		return bookingNoteMapper.findRate(pd);
	}

	public boolean saveOperateLog(FactBookingNote bookingNote , String operType , int status){
		Session session = Jurisdiction.getSession();
		User user = (User) session.getAttribute(Const.SESSION_USER);
		if(bookingNote == null){
			return false;
		}
		BillBusOptHis his = new BillBusOptHis();
		his.setStatus(status);
		his.setBillCode(bookingNote.getBillCode());
		his.setBusinessType(bookingNote.getBusinessType());
		his.setLadingBillCode(bookingNote.getLadingBillCode());
		his.setOperator(user.getUSER_ID());
		his.setOperatorType(operType);
		his.setOperateTime(new Date());
		return billBusOptHisMapper.insert(his) > 0;
	}



	@Override
	public List<PageData> finXiangzhu(PageData pd) {
		
		return bookingNoteMapper.finXiangzhu(pd);
	}


}
